package com.kaichaohulian.baocms.activity_newcreate;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaichaohulian.baocms.R;
import com.kaichaohulian.baocms.base.BaseMyActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 主界面
 * Created by ljl on 2016/12/11.
 */
@SuppressLint("ValidFragment")
public class BannerWebViewActivity extends BaseMyActivity {


    @BindView(R.id.img_return)
    ImageView imgReturn;
    @BindView(R.id.text_title_web)
    TextView textTitleWeb;
    @BindView(R.id.regist_web_wv)
    WebView registWebWv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bannerwebview);
        ButterKnife.bind(this);

        // 支持js
        registWebWv.getSettings().setJavaScriptEnabled(true);
        registWebWv.setWebChromeClient(new WebChromeClient());
        registWebWv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        registWebWv.getSettings().setUseWideViewPort(true);
        registWebWv.getSettings().setLoadWithOverviewMode(true);
        // 缩放
        registWebWv.getSettings().setSupportZoom(true);
        registWebWv.getSettings().setBuiltInZoomControls(false);

        registWebWv.addJavascriptInterface(this, "android");

        registWebWv.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {

                registWebWv.loadUrl("javascript:getvalue()");

                super.onPageFinished(view, url);
            }

        });

        String url = getIntent().getStringExtra("url");

        if (!TextUtils.isEmpty(url)) {

            registWebWv.loadUrl(url);
            textTitleWeb.setText(getIntent().getStringExtra("title"));
        } else {
            finish();
//            UtilToast.show(context, "注册时候返回的url没传过来  或者 根本没返回url");
        }
    }


    @OnClick({R.id.img_return, R.id.text_title_web, R.id.regist_web_wv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_return:
                finish();
                break;
            case R.id.text_title_web:
                break;
            case R.id.regist_web_wv:
                break;
        }
    }
}
